package com.example.mobile2021606170hsy0407homework;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    private TextView tvMainTitle;
    private Button btMainReset;
    private TextView tvMainOne;
    private RadioGroup radGupChoiceOption;
    private RadioButton radBtnMainA;
    private RadioButton radBtnMainB;
    private RadioButton radBtnMainC;
    private RadioButton radBtnMainD;
    private TextView tvMainTwo;
    private RadioGroup radGupChoiceOption1;
    private RadioButton radBtnMainA1;
    private RadioButton radBtnMainB1;
    private RadioButton radBtnMainC1;
    private RadioButton radBtnMainD1;
    private TextView tvMainThree;
    private RadioGroup radGupChoiceOption2;
    private RadioButton radBtnMainA2;
    private RadioButton radBtnMainB2;
    private RadioButton radBtnMainC2;
    private RadioButton radBtnMainD2;
    private TextView tvMainFour;
    private RadioGroup radGupChoiceOption3;
    private RadioButton radBtnMainA3;
    private RadioButton radBtnMainB3;
    private RadioButton radBtnMainC3;
    private RadioButton radBtnMainD3;
    private Button btMainSubmit;
    private TextView tvMainGrade;
    private EditText edtTxtMainGrade;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        radGupChoiceOption.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                RadioButton radioButton = findViewById(i);
                Log.i("RadioButton", radioButton.getText().toString());
            }
        });
        radGupChoiceOption1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                RadioButton radioButton = findViewById(i);
                Log.i("RadioButton", radioButton.getText().toString());
            }
        });
        radGupChoiceOption2.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                RadioButton radioButton = findViewById(i);
                Log.i("RadioButton", radioButton.getText().toString());
            }
        });
        radGupChoiceOption3.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                RadioButton radioButton = findViewById(i);
                Log.i("RadioButton", radioButton.getText().toString());
            }
        });

        btMainSubmit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                int optionID=   radGupChoiceOption.getCheckedRadioButtonId();
                int optionID1= radGupChoiceOption1.getCheckedRadioButtonId();
                int optionID2= radGupChoiceOption2.getCheckedRadioButtonId();
                int optionID3= radGupChoiceOption3.getCheckedRadioButtonId();
                if(optionID==R.id.radBtn_main_a &optionID==R.id.radBtn_main_b1& optionID==R.id.radBtn_main_b2& optionID==R.id.radBtn_main_c3) {
                    edtTxtMainGrade.setText("分数：100分");
                }else if(optionID1==R.id.radBtn_main_a & optionID1==R.id.radBtn_main_b1 & optionID1==R.id.radBtn_main_b2 &optionID1==R.id.radBtn_main_d) {
                    edtTxtMainGrade.setText("分数：75分");
                }else if(optionID2==R.id.radBtn_main_b & optionID2==R.id.radBtn_main_b2 & optionID2==R.id.radBtn_main_b2 & optionID2==R.id.radBtn_main_c) {
                    edtTxtMainGrade.setText("分数：60分");
                }else if(optionID3==R.id.radBtn_main_a &optionID3==R.id.radBtn_main_a & optionID3==R.id.radBtn_main_c & optionID3==R.id.radBtn_main_d2 ) {
                    edtTxtMainGrade.setText("分数：45分");
                }else if (optionID==-1||optionID1==-1||optionID2==-1||optionID3==-1){
                    Toast.makeText(MainActivity.this,"  请做选择", Toast.LENGTH_SHORT ).show();
                }else{
                    edtTxtMainGrade.setText("分数：0分");

                }
            }
        });
        btMainReset.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                radBtnMainA.setChecked(false);
                radBtnMainB.setChecked(false);
                radBtnMainC.setChecked(false);
                radBtnMainD.setChecked(false);
                radBtnMainA1.setChecked(false);
                radBtnMainB1.setChecked(false);
                radBtnMainC1.setChecked(false);
                radBtnMainD1.setChecked(false);
                radBtnMainA2.setChecked(false);
                radBtnMainB2.setChecked(false);
                radBtnMainC2.setChecked(false);
                radBtnMainD2.setChecked(false);
                radBtnMainA3.setChecked(false);
                radBtnMainB3.setChecked(false);
                radBtnMainC3.setChecked(false);
                radBtnMainD3.setChecked(false);
                edtTxtMainGrade.setText(" ");
                Toast.makeText(MainActivity.this,"重置成功",Toast.LENGTH_SHORT).show();
            }
        });
    }


    private void initView() {
        tvMainTitle = findViewById(R.id.tv_main_title);
        btMainReset = findViewById(R.id.bt_main_reset);
        tvMainOne = findViewById(R.id.tv_main_one);
        radGupChoiceOption = findViewById(R.id.radGup_choice_option);
        radBtnMainA = findViewById(R.id.radBtn_main_a);
        radBtnMainB = findViewById(R.id.radBtn_main_b);
        radBtnMainC = findViewById(R.id.radBtn_main_c);
        radBtnMainD = findViewById(R.id.radBtn_main_d);
        tvMainTwo = findViewById(R.id.tv_main_two);
        radGupChoiceOption1 = findViewById(R.id.radGup_choice_option1);
        radBtnMainA1 = findViewById(R.id.radBtn_main_a1);
        radBtnMainB1 = findViewById(R.id.radBtn_main_b1);
        radBtnMainC1 = findViewById(R.id.radBtn_main_c1);
        radBtnMainD1 = findViewById(R.id.radBtn_main_d1);
        tvMainThree = findViewById(R.id.tv_main_three);
        radGupChoiceOption2 = findViewById(R.id.radGup_choice_option2);
        radBtnMainA2 = findViewById(R.id.radBtn_main_a2);
        radBtnMainB2 = findViewById(R.id.radBtn_main_b2);
        radBtnMainC2 = findViewById(R.id.radBtn_main_c2);
        radBtnMainD2 = findViewById(R.id.radBtn_main_d2);
        tvMainFour = findViewById(R.id.tv_main_four);
        radGupChoiceOption3 = findViewById(R.id.radGup_choice_option3);
        radBtnMainA3 = findViewById(R.id.radBtn_main_a3);
        radBtnMainB3 = findViewById(R.id.radBtn_main_b3);
        radBtnMainC3 = findViewById(R.id.radBtn_main_c3);
        radBtnMainD3 = findViewById(R.id.radBtn_main_d3);
        btMainSubmit = findViewById(R.id.bt_main_submit);
        tvMainGrade = findViewById(R.id.tv_main_grade);

        edtTxtMainGrade = findViewById(R.id.edtTxt_main_grade);
    }
}
